'use strict';
exports.main = async (params, context) => {
	//event为客户端上传的参数
	const db = uniCloud.database();
	let res = [];
	if(params.uid){
		res =await db.collection("opendb-news-articles").field({title:!0,content:!0}).where({
			user_id: params.uid,
		}).get();
	}else if(params.id){
		res =await db.collection("opendb-news-articles").field({title:!0,content:!0}).where({
			_id: params.id,
		}).get();
	}else{
		res =await db.collection("opendb-news-articles").field({title:!0,content:!0}).limit(10).get();
	}
	let result = {};
	if(res.affectedDocs){
		result = {
			code:1,
			data:{
				total:res.affectedDocs,
				data:res.data
			},
			msg:'操作成功'
		}
	}else{
		result ={
			code:0,
			data:null,
			msg:'查询失败'
		}
	}
	//返回数据给客户端
	return result
};
